package vinux.web.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import vinux.service.common.base.BaseController;
import vinux.service.common.statics.Constant;
import vinux.service.common.statics.LogConstant;
import vinux.service.common.statics.SysConstant;
import vinux.service.common.util.RequestParameter;
import vinux.service.common.util.SysOut;
import vinux.service.core.utils.SystemLogUitls;
import vinux.service.entity.demo.Demo;


/**
 * 
 * shiro权限测试Controller
 * 
 * <p>
 * @author soywer
 * 
 * @version 1.0,2015年4月29日 <br/>
 * 
 */


@Controller
@Scope(Constant.SCOPE)
@RequestMapping("permission")
public class PermissionController extends BaseController {
	
	private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PermissionController.class);
	
	/**
	 * 展示权限demo首页面
	 * 访问地址:/permission/index.vhtml
	 * @return ModelAndView:/ftl/demo/index.ftl
	 * @throws Exception 
	 */
	@RequiresPermissions("permission/index")
	@RequestMapping("index")
	public ModelAndView permission(HttpServletRequest request){
//		SecurityUtils.getSubject().isPermitted("permission/index");
		//1,log输出begin
		SysOut.out("进入vinux.web.demo.controller.PermissionController类,调用permission方法,**输入**参数是:"+RequestParameter.getParameters(request).toString(),logger);
		//定义结果集
		Object returnStr= new Object();
		//定义请求url
		String url = "/permission/index.vhtml";
		//定义请求参数
		String params = null;
		//定义日志记录处理异常
		Exception ex = null;
		//定义日志记录主键ID，格式为：当前方法
		String indexID = SysConstant.METHOD_PERMISSION_INDEX;
		//定义日志记录业务描述，格式为：当前方法+sesionId
		String businessType = "展示权限demo首页面";
		
		try{
			//得到请求参数
			params = RequestParameter.getParameters(request).toString();
			
			//int a = 8/0;
			/**
			 * 
			 * 在这里编写方法主题
			 * 
			 * */
			
		}catch(Exception e){
			ex = e;
		}finally{
			//log输出end
			SysOut.out("进入vinux.web.demo.controller.PermissionController类,调用permission方法,**输出**参数是:"+returnStr.toString(),logger);
			SystemLogUitls.info(
								url, 
								params, 
								returnStr.toString(), 
								getClass(), 
								params, 
								ex, 
								LogConstant.DATA_DEAL_UPDATE, 
								LogConstant.SYSTEM_YANGLAO, 
								businessType, 
								indexID, 
								LogConstant.OTHER_LOG_COMMON);
		}
		return new ModelAndView("demo/index");
	}
	
	@RequiresPermissions("permission/test")
	@RequestMapping("test")
	public ModelAndView test(Demo entity){
		System.out.println("=============perission:test========");
		return new ModelAndView("demo/index");
	}
	
	
	@RequiresPermissions("permission/doit")
	@RequestMapping("doit")
	public ModelAndView doit(Demo entity){
		System.out.println("=============perission:doit========");
		return new ModelAndView("demo/index");
	}
	
}
